$(function() {
	
	jQuery.validator.addMethod("authority", function(value, element) {   
		return this.optional(element) || /^(ROLE_){1}[A-Z]+$/.test(value);   
	}, "请输入正确的权限标签");

	$("#add_role_form").validate({
		errorPlacement:function(error,element) {  
			element.parent().find(".verror").html(error);
		},
		rules:{
			"roles.name":{
				required:true,
				remote: {
					url: base + "oauth/roles/checkRoleName.action", 
					type: "POST", 
					data: {"roles.id": ($("#roles.id").val()), "roles.name": ($("#roles.name").val())}
				}
			},
			"roles.authority":{
				required: true,
				authority: true,
				remote: {
					url: base + "oauth/roles/checkAuthority.action", 
					type: "POST", 
					data: {"roles.id": ($("#roles.id").val()), "roles.authority": ($("#roles.authority").val())}
				}
			}
		},
		messages:{
			"roles.name": {
				required: "请输入角色名称", 
				remote: "该名称已被使用"
			},
			"roles.authority": {
				required: "请输入权限标签",
				authority: "请输入正确的权限标签",
				remote: "该标签已被使用"
			}
		}
	});
});